import { app } from "../../scripts/app.js";

const setComfyuiAiLogo = () => {
  const ComfyuiAiLogo = document.querySelector("#ComfyuiAiLogo");
  const parentObj = document.querySelector("#graph-canvas-container");
  // const topObj = document.querySelector("#comfyui-body-top");

  if (!ComfyuiAiLogo && parentObj) {
    setTimeout(() => {
      const contentObj = parentObj.querySelector(".p-splitterpanel-nested");
      // const top = topObj?.offsetHeight || 0;
      const img = Object.assign(document.createElement("img"), {
        src: "https://comfy.wifixc.com/comfyui-ai-logo-transparent.png",
        alt: "ComfyUI.AI logo",
        draggable: false,
        style: `position: absolute;width: 160px;height: auto;top: 20px; margin-left: 20px;pointer-events: none;user-select: none;`,
      });
      if (contentObj) {
        contentObj?.appendChild(img);
      } else {
        parentObj.insertBefore(img, parentObj.firstChild);
      }
    }, 1000);
  }
};

const ext = {
  name: "Comfy.InjectInfo",
  async setup() {
    setComfyuiAiLogo();
  },
};

app.registerExtension(ext);
